/*
 * Copyright 2017 JessYan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.dindang.maintenance.mvp.model.api.service;

import com.dindang.maintenance.mvp.model.api.MaintainApi;
import com.dindang.maintenance.mvp.model.entity.BaseResponse;
import com.dindang.maintenance.mvp.model.entity.Build;
import com.dindang.maintenance.mvp.model.entity.Repair;

import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import retrofit2.Retrofit;
import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.Headers;
import retrofit2.http.POST;

/**
 * ================================================
 * 展示 {@link Retrofit#create(Class)} 中需要传入的 ApiService 的使用方式
 * 存放关于用户的一些 API
 * <p>
 * Created by JessYan on 08/05/2016 12:05
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * ================================================
 */
public interface CommonService {
    String HEADER_API_VERSION = "Content-Type: application/x-www-form-urlencoded; charset=UTF-8";

    /**
     * 查询流程详情
     * @return
     */
    @Headers({"Domain-Name: " + MaintainApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("repairs/quertFlowDetail.do")
    Observable<BaseResponse<Repair.FlowDetail>> quertFlowDetail(@Field("id") String id);

    /**
     * 查询维修列表
     * @return
     */
    @Headers({"Domain-Name: " + MaintainApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
//    likeValue		模糊搜索值
//    bid			小区id
//    status		状态(1:待派单2:待接单3:待完成4:暂停中5:待回访6:已回访9已撤销)
//    applyArea	申请区域（1：私有区域，2：公共区域）
//    errType		故障类型
//    subType		故障子类型
//    cFrom		来源:1人工添加 2叮当管家 3微信报修(海纳)（公众号、生活号。。。 字典：1004）
//    createDateStart 	保修开始时间
//    createDateEnd  	 保修结束时间
//    appointDateStart 	申请开始时间
//    appointDateEnd 	申请结束时间
//    completeDateStart 	完成开始时间
//    completeDateEnd 	完成结束时间
    @POST("repairs/queryPageList.do")
    Observable<BaseResponse<Repair.RepairList>> queryPageList(
            @Field("page") int page,
                                                              @Field("rows") int rows,
                                                              @Field("likeValue") String likeValue,
                                                              @Field("userId") int userId,
                                                              @Field("corpId") String corpId,
                                                              @Field("bid") String bid,
                                                              @Field("status") String status,
                                                              @Field("applyArea") String applyArea,
                                                              @Field("errType") String errType,
                                                              @Field("subType") String subType	,
//                                                              @Field("cFrom") String cFrom,
                                                              @Field("createDateStart") String createDateStart,
                                                              @Field("createDateEnd") String createDateEnd,
                                                              @Field("appointDateStart") String appointDateStart,
                                                              @Field("appointDateEnd") String appointDateEnd,
                                                              @Field("completeDateStart") String completeDateStart,
                                                              @Field("completeDateEnd") String completeDateEnd);

    /**
     * 查询维修详情
     * @return
     */
//    @Headers({"Domain-Name: " + MaintainApi.APP_NAME, HEADER_API_VERSION})
//    @FormUrlEncoded
//    @POST("repairs/selectByPrimaryKey.do")
//    Observable<BaseResponse<Repair.R>> quertFlowDetail(@Field("id") String id);


    /**
     * 添加新流程信息
     * @return
     */
    @Headers({"Domain-Name: " + MaintainApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("repairs/insertFlow.do")
    Observable<BaseResponse> insertFlow(@Field("cRepId") String page,
                                        @Field("cCorpid") String cCorpid,
                                        @Field("cCreator") String cCreator,
                                        @Field("cCreatorid") String userId,
                                        @Field("cStatus") String cStatus,
                                        @FieldMap Map<String, String> map);

    /**
     * 完成
     * @return
     */
    @Headers({"Domain-Name: " + MaintainApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("repairs/complete.do")
    Observable<BaseResponse> complete(@Field("cRepId") int page,
                                        @Field("cRemark") int cCorpid,
                                        @Field("cStatus") String cCreator,
                                        @Field("file") int userId);

    /**
     * 修改
     * @return
     */
    @Headers({"Domain-Name: " + MaintainApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("repairs/update.do")
    Observable<BaseResponse> update(@Field("lId") String lId,
                                      @Field("fCost") String fCost,
                                      @Field("cRemark") String cRemark);

    /**
     * 查询权限小区
     * @param corpid 公司id（可不传）
     * @return
     */
    @Headers({"Domain-Name: " + MaintainApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("building/findBuilding.do")
    Observable<BaseResponse<List<Build.Building>>> findBuilding(@Field("isAdmin") String isAdmin,@Field("cId") String cId,@Field("corpId") String corpId);
    /**
     * 修改
     * @return
     */
    @Headers({"Domain-Name: " + MaintainApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("repairs/findRepairsByCorp.do")
    Observable<BaseResponse<List<Repair.MaintenancePeople>>> findRepairsByCorp(@Field("repId") String repId,
                                    @Field("corpId") String corpId);

    /**
     * 查询权限小区
     * @param corpid 公司id（可不传）
     * @return
     */
    @Headers({"Domain-Name: " + MaintainApi.APP_NAME, HEADER_API_VERSION})
    @FormUrlEncoded
    @POST("building/findBuilding.do")
    Observable<BaseResponse<List<Build.Building>>> findBuilding(@Field("corpid") String corpid);

}
